package com.ruoyi.project.channel.userGoodsInfo.controller;

import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.userGoodsInfo.domain.UserGoodsInfo;
import com.ruoyi.project.channel.userGoodsInfo.service.IUserGoodsInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 用户商品关系信息操作处理
 * 
 * @author CAIN
 * @date 2024-10-05
 */
@Controller
@RequestMapping("/channel/userGoodsInfo")
public class UserGoodsInfoController extends BaseController
{
    private String prefix = "channel/userGoodsInfo";
	
	@Autowired
	private IUserGoodsInfoService userGoodsInfoService;
	
	@RequiresPermissions("channel:userGoodsInfo:view")
	@GetMapping()
	public String userGoodsInfo()
	{
	    return prefix + "/userGoodsInfo";
	}
	
	/**
	 * 查询用户商品关系列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserGoodsInfo userGoodsInfo)
	{
		startPage();
        List<UserGoodsInfo> list = userGoodsInfoService.selectUserGoodsInfoList(userGoodsInfo);
		return getDataTable(list);
	}

	/**
	 * 查询用户商品关系列表
	 */
	@PostMapping("/list/user")
	@ResponseBody
	public TableDataInfo listByUser(UserGoodsInfo userGoodsInfo)
	{
		startPage();
		User user = ShiroUtils.getSysUser();
		userGoodsInfo.setUserId(user.getUserId());
		List<UserGoodsInfo> list = userGoodsInfoService.selectUserGoodsInfoList(userGoodsInfo);
		return getDataTable(list);
	}
	
	/**
	 * 导出用户商品关系列表
	 */
	@RequiresPermissions("channel:userGoodsInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserGoodsInfo userGoodsInfo)
    {
    	List<UserGoodsInfo> list = userGoodsInfoService.selectUserGoodsInfoList(userGoodsInfo);
        ExcelUtil<UserGoodsInfo> util = new ExcelUtil<UserGoodsInfo>(UserGoodsInfo.class);
        return util.exportExcel(list, "userGoodsInfo");
    }
	
	/**
	 * 新增用户商品关系
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存用户商品关系
	 */
	@RequiresPermissions("channel:userGoodsInfo:add")
	@Log(title = "用户商品关系", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserGoodsInfo userGoodsInfo)
	{		
		return toAjax(userGoodsInfoService.insertUserGoodsInfo(userGoodsInfo));
	}

	/**
	 * 修改用户商品关系
	 */
	@GetMapping("/edit/{orderId}")
	public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
	{
		UserGoodsInfo userGoodsInfo = userGoodsInfoService.selectUserGoodsInfoById(orderId);
		mmap.put("userGoodsInfo", userGoodsInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存用户商品关系
	 */
	@RequiresPermissions("channel:userGoodsInfo:edit")
	@Log(title = "用户商品关系", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserGoodsInfo userGoodsInfo)
	{		
		return toAjax(userGoodsInfoService.updateUserGoodsInfo(userGoodsInfo));
	}
	
	/**
	 * 删除用户商品关系
	 */
	@RequiresPermissions("channel:userGoodsInfo:remove")
	@Log(title = "用户商品关系", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userGoodsInfoService.deleteUserGoodsInfoByIds(ids));
	}
	
}
